package com.youxue.teachin.set.main;

import com.library.uiframework.activity.WrapActionBarFragmentActivity;
import com.library.uiframework.widget.actionbar.ActionBarLayout.Action;
import com.youxue.teachin.R;
import com.youxue.teachin.common.utils.DefaultSubscriber;
import com.youxue.teachin.user.login.usercase.LoginUserCase;
import com.youxue.teachin.user.userSystem.UserSystem;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-05 21:31
 * @version: 9.1.0
 */
public class SetMainAcitvity extends WrapActionBarFragmentActivity {
    @Override
    protected Class wrapFragmentClass() {

        return SetFragment.class;
    }

    @Override
    protected void onInitActionBar() {
        super.onInitActionBar();
        setTitle("我");
        int color = getResources().getColor(R.color.set_actionbar_color);
        getActionBarLayout().setActionBarBackground(color);
        setStatusBarColor(color);
        getActionBarLayout().setTitleColorRes(R.color.cl_1);
    }

    @Override
    protected Action createBack() {
        return addLeftImageAction(ACTION_BACK, R.drawable.top_return);
    }

    @Override
    protected Action createMenu() {
        return addImageAction(ACTION_MENU, R.drawable.sign_out);
    }

    @Override
    protected void onActionClick(int actionId, Action action) {
        super.onActionClick(actionId, action);
        if (ACTION_MENU == actionId) {
            new LoginUserCase()
                .loginOut()
                .subscribe(new DefaultSubscriber<Void>(){
                    @Override
                    public void onNext(Void aVoid) {
                        super.onNext(aVoid);
                        UserSystem.getInstance().sendLoginOoutSuccess();
                        finish();
                    }
                });

        }
    }

    @Override
    protected boolean needMenuAction() {
        return true;
    }
}
